package com.carsystems.controller;

import com.carsystems.mapper.PolicyOfCarMapper;
import com.carsystems.pojo.PolicyOfCar;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
public class PolicyOfCarController {

    @Autowired
    PolicyOfCarMapper policyMapper;

    //查看全部政策
    @GetMapping("/querPolicyList")
    public List<PolicyOfCar> querPolicyList() {
        List<PolicyOfCar> policyOfCarList = policyMapper.querPolicyList();
        return policyOfCarList;
    }

    //按照zc_id查询
    @GetMapping("/querPolicyByPrimaryKey")
    public PolicyOfCar querPolicyByPrimaryKey(Integer zc_id) {

        return policyMapper.querPolicyByPrimaryKey(zc_id);
    }

    //增加一个政策信息
    @ResponseBody
    @PostMapping("/addPolicy")
    public String addPolicy(@RequestBody PolicyOfCar policy) {
        policyMapper.addPolicy(policy);
        if (policy != null) {
            return "success";
        } else {
            return "fail";
        }
    }

    //修改公司信息
    @ResponseBody
    @PostMapping("/updatePolicy")
    public String updatePolicy(@RequestBody PolicyOfCar policy){
        int row = policyMapper.updatePolicy(policy);
        policyMapper.querPolicyByPrimaryKey(policy.getZc_id());
        if (row==1){
            return "success";
        }else {
            return "fail";
        }
    }

    //删除公司
    @ResponseBody
    @GetMapping("/deletePolicy")
    public String deletePolicy(PolicyOfCar policy){
        int row = policyMapper.deletePolicy(policy.getZc_id());
        if (row == 1){
            return "success";
        }else {
            return "fail";
        }
    }
}
